﻿using DAL;
using IService;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Service
{
    public class WhStockTakeService : IWhStockTakeService
    {
        private readonly WhStockTakeDal _dal;
        private readonly AppDbContext _dbContext; // 需要注入DbContext用于直接查询
        public WhStockTakeService(WhStockTakeDal dal, AppDbContext dbContext)
        {
            _dal = dal;
            _dbContext = dbContext;
        }
        /// <summary>
        /// 获取下一个盘点单号
        /// </summary>
        /// <returns>盘点单号</returns>
        public async Task<string> GetNextInventoryNoAsync()
        {
            return await _dal.GetNextInventoryNoAsync();
        }
        public Task<int> CreateAsync(WhStockTake data)
        {
            _dbContext.WhStockTake.Add(data);
            return _dbContext.SaveChangesAsync();
        }

        public Task<int> DeleteAsync(long Id)
        {
            return _dal.DeleteAsync(Id);
        }

        public async Task<List<WhStockTake>> GetAll()
        {
            return await _dal.GetAllAsync();
        }

        public Task<WhStockTake> GetByIdAsync(long Id)
        {
            return _dal.GetByIdAsync(Id);
        }

        public Task<int> UpdateAsync(WhStockTake data)
        {
            _dbContext.WhStockTake.Update(data);
            return _dbContext.SaveChangesAsync();
        }
    }
}